<?php
  include ('header.php');
  require_once('includes/db_connect.inc.php');
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title><?php echo $actions['view_status']?></title>	
</head>
<body>
<?php
//$_GET['inv_numb']='10483899';
if(isset($_GET['inv_number'])){
$_SESSION[inv_numb]=$_GET['inv_number'];
}
if($_POST['date_open']){
$_SESSION['date_open']=$_POST['date_open'];
}else 
$_SESSION['date_open']='01.01.2011';
if($_POST['date_end']){
$_SESSION['date_end']=$_POST['date_end'];
}else $_SESSION['date_end']='31.12.2011';
?>
<script type="text/javascript">
$(document).ready(function(){
  // ---- Календарь -----
  $('.data_open').attachDatepicker();
});
</script>


<form action=<?php echo $_SERVER['PHP_SELF'] ?> method=POST name='view_stat_auditory'>


<center>
Початкова дата: <input type="text" class='data_open' name="date_open" id="data_open_id" size=10 value='<?php echo $_SESSION[date_open] ?>' onchange='document.forms["view_stat_auditory"].submit();'>
кінцева дата: <input type="text"  class='data_open' name="date_end" id="data_open_id" size=10 value='<?php echo $_SESSION[date_end] ?>'  onchange='document.forms["view_stat_auditory"].submit();'>
<br><br>
</center>
<TABLE  class="view_stat_auditory" >
<TR >
	<td class="view_stat_auditory" width='100' colspan=6> Інв. номер  <?php echo $_SESSION[inv_numb] ?></td>
	</tr>
<TR >
	
	<td class="view_stat_auditory" width='120'> Назва предмету</td>
	<td class="view_stat_auditory" width='100'> Старий статус</td>
	<td class="view_stat_auditory" width='100'> Новий статус </td>
	<td class="view_stat_auditory" width='60'> Дата переміщення</td>
	<td class="view_stat_auditory" width='10'>Користувач</td>
	<td class="view_stat_auditory" width='10'>Коментарій</td>
 </tr>

<?php
if(!$_GET['page']){
$_GET['page']=1;
}

//echo $_SESSION[date_open];
$sql="SELECT *
FROM `all_inventory_log` 
where  status<>status_new 
and inv_numb='".$_SESSION[inv_numb]."'
and cast(str_to_date(date_change, '%d.%m.%Y') as datetime )>=cast(str_to_date('".$_SESSION[date_open]."', '%d.%m.%Y') as datetime )
and cast(str_to_date(date_change, '%d.%m.%Y') as datetime )<=cast(str_to_date('".$_SESSION[date_end]."', '%d.%m.%Y') as datetime )";
//echo $sql;
//Запрос для подсчета строк
$sql5 ="select count(*) 
FROM `all_inventory_log` 
where  status<>status_new 
and inv_numb='".$_SESSION[inv_numb]."'
and cast(str_to_date(date_change, '%d.%m.%Y') as datetime )>=cast(str_to_date('".$_SESSION[date_open]."', '%d.%m.%Y') as datetime )
and cast(str_to_date(date_change, '%d.%m.%Y') as datetime )<=cast(str_to_date('".$_SESSION[date_end]."', '%d.%m.%Y') as datetime )";

$process5=mysql_query($sql5, $db);
$count = mysql_fetch_array($process5);
//Получаем целочисленное значение страниц
$count_page=ceil($count[0]/$_SESSION['count_for_page']);
//берем старторвый номер для sql запроса страниц
$start_number=($_GET['page']-1)*$_SESSION['count_for_page'];
//echo $_GET[page];
if (($count_page>1)  && ($_GET[page]!='all')){
$sql.=" LIMIT ".$start_number.",  ".$_SESSION['count_for_page']." ";
}


$process=mysql_query($sql, $db);
$i=1;
echo $row[true1];
while ($row = mysql_fetch_array($process, $i)){ 
echo "<tr>";

	echo "<td class=\"view_stat_auditory\" >".$row[item_name]."</td>";
	$sql2="SELECT * FROM item_status where status_id='".$row[status]."'";
    $process2=mysql_query($sql2, $db);
	$row2 = mysql_fetch_array($process2);
	echo "<td class=\"view_stat_auditory\" >".$row2[status_name]."</td>";

	$sql2="SELECT * FROM item_status where status_id=".$row[status_new];  
    $process2=mysql_query($sql2, $db);
	$row2 = mysql_fetch_array($process2);
	echo "<td class=\"view_stat_auditory\" >".$row2[status_name]."</td>";
	echo "<td class=\"view_stat_auditory\" >".$row[date_change]."</td>";
	echo "<td class=\"view_stat_auditory\" >".$row[user]."</td>";
	echo "<td class=\"view_stat_auditory\" >".$row[comment]."</td>";
echo "</tr>";
}

?>
 </table>
 </form>
 
<?php
if ($count_page>1){
	echo "<center>".$texts[pages]." ";
	if ($_GET[page]!='all'){
	echo "<a href=".$_SERVER['PHP_SELF']."?page=all>".$texts[all_pages]."</a> ";
	}
	else echo $texts[all_pages]." ";
	for ($i=1;$i<=$count_page;$i++){
	if ($_GET[page]!=$i){
		echo "<a href=".$_SERVER['PHP_SELF']."?page=".$i.">$i</a> ";
		}
	else echo "$i ";
	}
	echo "</center>";
}
  include ('footer.php');
?>

</body>
</html>